clear all;
load 'data_log.txt'

neuron_id = data_log(:,1);
time = data_log(:,2);
neuron_vm = data_log(:,3);
neuron_gk = data_log(:,4);
neuron_gkir2 = data_log(:,5);
neuron_t_last = data_log(:,6);

num_neurons = max(neuron_id) + 1;

%Process the file and plot vm data for one neuron
j=1;
k=1;
l=1;
for i=1:length(neuron_id)
    if(neuron_id(i) == 0 )
        neuron_0_vm(j) = neuron_vm(i);
%         neuron_0_t(j) = time(i);    
%         neuron_0_gk(j) = neuron_gk(i);
%         neuron_0_Ica(j) = neuron_Ica(i);
%         neuron_0_t_last(j) = neuron_t_last(i);
        j = j+1;
    end
    if(neuron_id(i) == 3 )
        neuron_3_vm(k) = neuron_vm(i);
%         neuron_1_t(k) = time(i);    
%         neuron_1_gk(k) = neuron_gk(i);
%         neuron_1_Ica(k) = neuron_Ica(i);
%         neuron_1_t_last(k) = neuron_t_last(i);
        k = k+1;
    end
    if(neuron_id(i) == 2 )  
        neuron_2_vm(l) = neuron_vm(i);
        neuron_2_t(l) = time(i);  
        neuron_2_gk(l) = neuron_gk(i);
        neuron_2_gkir2(l) = neuron_gkir2(i);
%         neuron_2_t_last(l) = neuron_t_last(i);
        l = l+1;
    end
end
% This should be linear to indicate sim is running smoothly.
% figure; hold on;
% plot(neuron_0_t); %Plot of simulation time vs real time.
figure; hold on;
%plot(neuron_0_vm,'g');
plot(neuron_3_vm,'b');
plot(neuron_2_vm,'g');
plot(neuron_2_gk,'k');
plot(neuron_2_gkir2,'r');


title('Bursting Ca-K-Na Channel Neuron');
xlabel('Time (simulation time step)');
ylabel('Membrane Potential: Scaled 0-10');
%legend('Neuron0','Neuron3','Neuron2','Neuron2 G_k','Neuron2 G_kir2');
legend('Neuron3','Neuron2','Neuron2 G_k','Neuron2 G_kir2');
axis tight;
